package com.xxq.gulimall.product.service.impl;

import com.xxq.gulimall.product.entity.AttrGroupEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxq.common.utils.PageUtils;
import com.xxq.common.utils.Query;

import com.xxq.gulimall.product.dao.BrandDao;
import com.xxq.gulimall.product.entity.BrandEntity;
import com.xxq.gulimall.product.service.BrandService;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BrandEntity> queryWrapper = new QueryWrapper<>();

        return new PageUtils(getPage(params, queryWrapper));
    }

    // 预分页
    private IPage<BrandEntity> getPage(Map<String, Object> params, QueryWrapper<BrandEntity> queryWrapper) {
        String key = (String) params.get("key");
        if (key != null && !key.isEmpty()) {
            queryWrapper.like("name", key).or()
                    .like("descript", key).or()
                    .like("first_letter", key);
        }

        return this.page(
                new Query<BrandEntity>().getPage(params),
                queryWrapper
        );
    }

}